#include <iostream>
#include <memory>

class Fruit
{
public:
    Fruit() {}
    virtual void show() = 0;
};

class Apple :public Fruit
{
public:
    Apple(){}
    virtual void show() override
    {
        std::cout << "我是一个苹果" << std::endl;
    }
};

class Banana :public Fruit
{
public:
    Banana(){}
    virtual void show() override
    {
        std::cout << "我是一个香蕉" << std::endl;
    }
};

class FruitFactory
{
public:
    static std::shared_ptr<Fruit> create(const std::string &name)
    {
        if (name == "苹果")
        {
            return std::make_shared<Apple>();
        }
        else if(name == "香蕉")
        {
            return std::make_shared<Banana>();
        }

        return std::shared_ptr<Fruit>();
    }
};

int main()
{
    std::shared_ptr<Fruit> fruit = FruitFactory::create("苹果");
    fruit->show();
    fruit = FruitFactory::create("香蕉");
    fruit->show();
    return 0;
}